package com.wp.design.create.singleton.doblecheck;

public class LazyDoubleCheckSingleton {
	private LazyDoubleCheckSingleton() {
	}

	// volatile 防止重排序问题（java是这样分配的，1先分配内存->2初始化对象->3将对象指定内存地址->4访问对象，其中2 和3步骤是随机的）
	private volatile static LazyDoubleCheckSingleton lazyDoubleCheckSingleton = null;
	public static LazyDoubleCheckSingleton getInstance(){
		if (lazyDoubleCheckSingleton == null){
			synchronized (LazyDoubleCheckSingleton.class){
				if (lazyDoubleCheckSingleton == null){
					return new LazyDoubleCheckSingleton();
				}
			}
		}
		return lazyDoubleCheckSingleton;
	}
}
